
package com.naza.rpc.netty;

import com.naza.rpc.core.RpcSystemConfig;
import com.naza.rpc.model.RpcRequest;
import com.naza.rpc.model.RpcResponse;

import java.util.Map;
import java.util.concurrent.Callable;

/**
 * RPC服务端 业务处理任务包装
 * @author yl
 */
public class RecvInitializeTaskFacade {
    private RpcRequest request;
    private RpcResponse response;
    private Map<String, Object> handlerMap;
    private boolean isMetrics = RpcSystemConfig.SYSTEM_PROPERTY_JMX_METRICS_SUPPORT;
    private boolean jmxMetricsHash = RpcSystemConfig.SYSTEM_PROPERTY_JMX_METRICS_HASH_SUPPORT;

    public RecvInitializeTaskFacade(RpcRequest request, RpcResponse response, Map<String, Object> handlerMap) {
        this.request = request;
        this.response = response;
        this.handlerMap = handlerMap;
    }

    public Callable<Boolean> getTask() {
        return isMetrics ? getMetricsTask() : new RpcRecvInitializeTaskAdapter(request, response, handlerMap);
    }

    private Callable<Boolean> getMetricsTask() {
        return jmxMetricsHash ? new HashMessageRecvInitializeTask(request, response, handlerMap) : new RpcRecvInitializeTask(request, response, handlerMap);
    }
}

